package com.taskcollection.mybitsspring;

import com.sun.org.apache.bcel.internal.generic.NEW;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.FactoryBean;

/**
 * Created by Administrator on 2016/8/14 0014.
 */
public class fanxing <T> implements FactoryBean {
    private Class<T> obj;

    public Class<T> getObj() {
        return obj;
    }

    public void setObj(Class<T> obj) {
        this.obj = obj;
    }

    private SqlSessionFactory sqlSessionFactory;

    public SqlSessionFactory getSqlSessionFactory() {
        return sqlSessionFactory;
    }

    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public Object getObject() throws Exception {
        return sqlSessionFactory.openSession().getMapper(obj);
    }

    @Override
    public Class<?> getObjectType() {
        return obj.getClass();
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
